//
//  RootViewController.h
//  TVLive
//
//  Created by sid on 21/05/10.
//  Copyright __MyCompanyName__ 2010. All rights reserved.
//

#import "MyMovieViewController.h"
#import "TVLiveAppDelegate.h"

NSString * const OverlayViewTouchNotification = @"overlayViewTouch";

@implementation MyMovieViewController
@synthesize overlayView;
@synthesize movieURL;

- (IBAction)playMovieButtonPressed:(id)sender
{
    TVLiveAppDelegate *appDelegate = (TVLiveAppDelegate *)[[UIApplication sharedApplication] delegate];

	[appDelegate initAndPlayMovie:[self localMovieURL]];

	NSArray *windows = [[UIApplication sharedApplication] windows];
	if ([windows count] > 1)
	{
		UIWindow *moviePlayerWindow = [[UIApplication sharedApplication] keyWindow];
		[moviePlayerWindow addSubview:self.overlayView];
	}
}

- (NSURL *)localMovieURL
{
    if (self.movieURL == nil)
    {
        NSBundle *bundle = [NSBundle mainBundle];
        if (bundle) 
        {
            NSString *moviePath = [bundle pathForResource:@"Movie" ofType:@"m4v"];
            if (moviePath)
            {
                self.movieURL = [NSURL fileURLWithPath:moviePath];
            }
        }
    }
    
    return self.movieURL;
}

// Touches in the overlay view (not in the overlay button)
// post the "overlayViewTouch" notification and will send
// the overlayViewTouches: message
- (void)overlayViewTouches:(NSNotification *)notification
{
    // Handle touches to the overlay view (MyOverlayView) here... 
}

// Action method for the overlay view (MyOverlayView) button
- (IBAction)overlayViewButtonPress:(id)sender
{
    // Handle touches to the overlay view 
    // button here... 
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
    // Return YES for supported orientations
    return YES;
}

- (void)dealloc
{
    [movieURL release];
    [super dealloc];
}

@end